package com.grape.dp.singleton.双重检验锁;

/**
 * 描述:SingletonV3Test
 * @author: myx
 * @date: 2019/7/29 0029
 * Copyright © 2019-grape. All rights reserved.
 */
public class SingletonV3Test {
    public static void main(String[] args) throws Exception {
        for (int i = 0; i < 100; i++) {
            new Thread(new Runnable() {
                public void run() {
                    SingletonV3 singletonV3 = null;
                    try {
                        singletonV3 = SingletonV3.getSingletonV3();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "," + singletonV3);
                }
            }).start();
        }
//        // 单例基本原则；保证在单个jvm中不重复创建
//        SingletonV3 singletonV1 = SingletonV3.getSingletonV3();
//        //  如何去破解单例  使用java的反射技术 、序列化技术
//        Constructor<SingletonV3> declaredConstructor = SingletonV3.class.getDeclaredConstructor();
//        declaredConstructor.setAccessible(true);
//        // 使用java的反射技术创建
//        SingletonV3 singletonV2 = declaredConstructor.newInstance();
//        System.out.println(singletonV1 == singletonV2);
//        // 如何防御反射技术破解单例
    }
}
